package com.pig4cloud.pigx.wallet.websocket.handler;

import com.pig4cloud.pigx.common.customize.api.annotation.OpenApi;
import com.pig4cloud.pigx.common.websocket.handler.JsonMessageHandler;
import com.pig4cloud.pigx.wallet.websocket.manager.WsManager;
import com.pig4cloud.pigx.wallet.websocket.message.SubscribeMessage;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;


@Slf4j
@Component
@AllArgsConstructor
@OpenApi
public class SubscribeHandler implements JsonMessageHandler<SubscribeMessage> {
    @Autowired
    private WsManager wsManager;

    @Override
    public void handle(WebSocketSession session, SubscribeMessage message) {
        wsManager.subscribe(session, message);
    }

    @Override
    public String type() {
        return SubscribeMessage.TYPE;
    }

    @Override
    public Class<SubscribeMessage> getMessageClass() {
        return SubscribeMessage.class;
    }
}
